package com.qiyu.mall.user.provider.service;

import com.qiyu.mall.user.interfaces.constants.RoleGroupConstants;
import com.qiyu.mall.user.interfaces.dto.CommunityAssociateDTO;
import com.qiyu.mall.user.interfaces.dto.RoleGroupDTO;
import com.qiyu.mall.user.interfaces.service.RoleService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * @author idea
 * @data 2020/2/13
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private CommunityAssociateServiceImpl communityAssociateService;

    @Override
    public RoleGroupDTO getMiniRoleGroup(Integer accountId) {
        CommunityAssociateDTO communityAssociateDTO = communityAssociateService.getByAccountId(accountId);
        if(communityAssociateDTO!=null){
            return RoleGroupDTO.builder()
                    .roleId(RoleGroupConstants.RoleGroupEnum.COMMUNITY_ASSOCIATE.getCode())
                    .accountId(accountId).build();
        }else {
            return RoleGroupDTO.builder()
                    .roleId(RoleGroupConstants.RoleGroupEnum.USER.getCode())
                    .accountId(accountId).build();
        }
    }
}
